
package com.huaweicloud.saaslanding.install.config.datasource;

import static com.huaweicloud.saaslanding.basic.constant.BizConstant.BUSINESS_PACKAGE;
import static com.huaweicloud.saaslanding.basic.constant.BizConstant.UTIL_PACKAGE;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.huaweicloud.saaslanding.basic.database.datasource.BaseMasterDatabaseConfiguration;
import com.huaweicloud.saaslanding.basic.database.datasource.ObjectProviderEntity;
import com.huaweicloud.saaslanding.basic.database.properties.DatabaseProperties;

import lombok.extern.slf4j.Slf4j;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Repository;

/**
 * 一句话功能简述
 * 功能详细描述
 *
 * @version V1.0
 * @since 2022-01-18
 */
@Configuration
@Slf4j
@MapperScan(basePackages = {UTIL_PACKAGE,
        BUSINESS_PACKAGE}, annotationClass = Repository.class, sqlSessionFactoryRef = BaseMasterDatabaseConfiguration.DATABASE_PREFIX
                + "SqlSessionFactory")
@EnableConfigurationProperties({MybatisPlusProperties.class})
@ConditionalOnExpression("!'DATASOURCE'.equals('${saaslanding.database.multiTenantType}')")
public class TenantDatabaseAutoConfiguration extends BaseMasterDatabaseConfiguration {

    public TenantDatabaseAutoConfiguration(MybatisPlusProperties properties, DatabaseProperties databaseProperties,
            ResourceLoader resourceLoader, ApplicationContext applicationContext, ObjectProviderEntity providerEntity) {
        super(properties, databaseProperties, resourceLoader, applicationContext, providerEntity);
        log.debug("检测到 saaslanding.database.multiTenantType!=DATASOURCE，加载了 TenantDatabaseAutoConfiguration");
    }
}
